
package trim.differentmaterials.core.initializers;

import trim.differentmaterials.core.*;
import trim.differentmaterials.coefficients.*;
import trim.differentmaterials.generator.columns.*;

/**
 *
 * @author Podorov Alexander
 */

public class NremTrimCoreInitializer extends TrimCoreInitializer
{
    public NremTrimCoreInitializer(TrimCore core, Coefficients coefficients)
    {
        super(core, coefficients);
    }

    public void setInverseMatrix()
    {
        for (int i = 0; i < materialCount + formatCount; i++)
        {
            inverseMatrix[i][i] = 1.0;
        }
    }

    private double getRequireValue()
    {
        int materialArea = 0;
        for (int i = 0; i < materialCount; i++)
        {            
            materialArea += materialStock[i].getMaterial().getLength() * materialStock[i].getCount();
        }

        int formatArea = 0;
        for (int i = 0; i < formatCount; i++)
        {            
            formatArea += formatOrder[i].getFormat().getLength() * formatOrder[i].getCount();
        }

        return (double)materialArea / (double)formatArea;
    }
    
    public void setRightPart()
    {
        double require = getRequireValue();

        for (int i = 0; i < formatCount; i++)
        {            
            rightPart[i] = (int)(formatOrder[i].getCount() * require) + 1;
        }

        for (int i = 0; i < materialCount; i++)
        {
            rightPart[i + formatCount] = materialStock[i].getCount();
        }
    }    

    public void setPatterns()
    {
        for (int i = 0; i < formatCount; i++)
        {
            int[] items = new int[materialCount + formatCount];
            items[i] = 1;            
            patterns.add(new PositiveFormatGap(items, - Double.MAX_VALUE, coefficients.getCoefficient(PositiveFormatGap.class), i));
        }
        for (int i = 0; i < materialCount; i++)
        {
            int[] items = new int[materialCount + formatCount];
            items[i + formatCount] = 1;            
            patterns.add(new ArtificialColomn(items, - Double.MAX_VALUE, coefficients.getCoefficient(ArtificialColomn.class), i));
        }
    }
}
